#!groovy

def branch = params.get("JETTY_BRANCH", "jetty-10.0.x")
def owner = params.get("REPO_OWNER", "eclipse")
def jdk = params.get("JDK", "jdk11")
def jmhJarPath = params.get("jmhJarPath", "tests/jetty-jmh/target/benchmarks.jar")
currentBuild.description = "Build branch $branch with jdk $jdk"

node("linux") {
    // System Dependent Locations
    def mvnName = 'maven3.5'
    def localRepo = "${env.JENKINS_HOME}/${env.EXECUTOR_NUMBER}"
    def settingsName = 'oss-settings.xml'
    def mavenOpts = '-Xms1g -Xmx4g -Djava.awt.headless=true'


    stage("Checkout") {
        git url: "https://github.com/$owner/jetty.project.git", branch: "$branch"

    }

    stage("Compile") {
        timeout(time: 15, unit: 'MINUTES') {
            withMaven(
                    maven: mvnName,
                    jdk: jdk,
                    publisherStrategy: 'EXPLICIT',
                    globalMavenSettingsConfig: settingsName,
                    mavenOpts: mavenOpts,
                    mavenLocalRepo: localRepo) {
                sh "mvn -V -B clean install -DskipTests -T6 -e -pl :jetty-jmh -am"
            }
        }
        stash name: 'perf-tests', includes: jmhJarPath
    }
}

// jmh run
node('jmh-build-node') {
    stage("jmh-run") {
        timeout(time: 210, unit: 'MINUTES') {
            withEnv(["JAVA_HOME=${tool "$jdk"}"]) {
                unstash name: 'perf-tests'
                sh "rm -rf jmh_results"
                sh "mkdir jmh_results"
                sh "${env.JAVA_HOME}/bin/java -jar $jmhJarPath -rff jmh_results/jmh_result.json -rf json  -foe true -i 3 -t 3 -wi 3"
                jmhReport 'jmh_results/jmh_result.json'
            }
        }
    }
}


// vim: et:ts=2:sw=2:ft=groovy
